// api/topic.js
import { request } from "@/utils/request";




// 获取经书列表的参数接口
interface GetTopicListParams {
    keyword?: string;
    pageNum: number;
    pageSize: number;
}


interface JingshuUser {
    id: number;
    username: string;
    password: string;
    phoneNumber: string;
    isActive: number;
    isAdmin: number;
    level: number;
    birthDate: null,
    address: null,
    gender: number;
    avatarUrl: null,
    dharmaName: string;
    totalMerit: number;
    createTime: string;
    updateTime: string;
}

interface Comment {
    id: number;
    topicId: number;
    userId: number;
    content: string;
    side: number;
    status: number;
    createTime: string;
    updateTime: string;
}


  export interface Topic {
    id: number;
    userId: number;
    title: string;
    content: string;
    status: number;
    prosTitle: string;
    consTitle: string;
    coverUrl: string;
    positive: string;
    negative: string;
    createTime: string;
    updateTime: string;
    user: JingshuUser;
    comments: Array<Comment>;
} 



export interface ResponseData<T> {
    code: number;
    row?: T;
    msg: string;
}


export function createIncense(data:any) {
  return request.post('/scripture/incense/add', data)
}

export const getIncenseList = async (params: GetTopicListParams) => {
  try {
    const { keyword = '', pageNum } = params;
    const response = await request.get('/scripture/incense/list', {
      data: {
        keyword,
        pageNum,
        pageSize: 5
      }
    });
    return response as any;
  } catch (error) {
    console.error('获取供香列表失败:', error);
    return {
      code: -1,
      msg: '网络请求失败',
      rows: [],
      total: 0
    };
  }
};


export const getRankNumber= async () => {
  try {
    const response = await request.get('/scripture/incense/rankNumber');
    return response as any;
  } catch (error) {
    console.error('获取供香列表失败:', error);
    return {
      code: -1,
      msg: '网络请求失败',
      rows: [],
      total: 0
    };
  }
};



